/*

	T. A12 Heterogeneous Effects of SNED on Teacher Outcomes I, Teacher-Level

*/


global replica_dir="<add path to your working directory>"
global data_dir=	"$replica_dir/data"
global output_dir=	"$replica_dir/output"

use "$data_dir/tlvl_fin.dta", clear  

	
					
/*----------------------------------------------------------------------------
	
	Multiple hypothesis testing
*/


global depvars "horas_contrato tea_classhrs" 
global indepvars "municip rural_rbd_tm1 gender_tm1 tit_educ_tm1 permanent_tm1 tea_admin_tm1 multsch_tm1 i.sned_yr i.hg"


eststo clear


/*------------------------------------------------------------------------------ 
	Regressions
	
	All
*/

eststo clear


foreach yvar of global depvars{
	
eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if abs(st_ind25) <= 1.5 & cut25<mean_cut25, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if abs(st_ind10) <= 1.5 & cut10<mean_cut10, vce(cluster rbd)

eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if abs(st_ind25) <= 1.5 & cut25>=mean_cut25, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if abs(st_ind10) <= 1.5 & cut10>=mean_cut10, vce(cluster rbd)

}	


/*------------------------------------------------------------------------------

	PV
	
*/				
	
	


foreach yvar of global depvars{
	
eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_pv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_pv, vce(cluster rbd)

eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, vce(cluster rbd)

}				


/*------------------------------------------------------------------------------

	MV
	
*/		
 

foreach yvar of global depvars{
	
eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_mv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_mv, vce(cluster rbd)

eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_mv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_mv, vce(cluster rbd)

}				


/*----------------------------------------------------------------------------
	
	Multiple hypothesis testing
*/

rwolf2 ///	
	(reg horas_contrato_tp1 horas_contrato_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if 				 		abs(st_ind25) <= 1.5 & cut25<mean_cut25,  vce(cluster rbd)) ///
	(reg horas_contrato_tp1 horas_contrato_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if 				 		abs(st_ind10) <= 1.5 & cut10<mean_cut10,  vce(cluster rbd)) /// 
	(reg horas_contrato_tp1 horas_contrato_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if 				 		abs(st_ind25) <= 1.5 & cut25>=mean_cut25, vce(cluster rbd)) ///
	(reg horas_contrato_tp1 horas_contrato_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if 				 		abs(st_ind10) <= 1.5 & cut10>=mean_cut10, vce(cluster rbd)) /// 
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if 					 	abs(st_ind25) <= 1.5 & cut25<mean_cut25,  vce(cluster rbd)) ///
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if 				 		abs(st_ind10) <= 1.5 & cut10<mean_cut10,  vce(cluster rbd)) /// 
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if 				   abs(st_ind25) <= 1.5 & cut25>=mean_cut25, vce(cluster rbd)) ///
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if 			   abs(st_ind10) <= 1.5 & cut10>=mean_cut10, vce(cluster rbd)) /// 
	(reg horas_contrato_tp1 horas_contrato_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 &  abs(st_ind25) <= 1.5 & cut25< mean_cut25_pv, vce(cluster rbd)) ///
	(reg horas_contrato_tp1 horas_contrato_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 &  abs(st_ind10) <= 1.5 & cut10< mean_cut10_pv, vce(cluster rbd)) /// 
	(reg horas_contrato_tp1 horas_contrato_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 &  abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, vce(cluster rbd)) ///
	(reg horas_contrato_tp1 horas_contrato_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 &  abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, vce(cluster rbd)) /// 
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 &  abs(st_ind25) <= 1.5 & cut25< mean_cut25_pv, vce(cluster rbd)) ///
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 &  abs(st_ind10) <= 1.5 & cut10< mean_cut10_pv, vce(cluster rbd)) /// 
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 &  abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, vce(cluster rbd)) ///
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 &  abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, vce(cluster rbd)) /// 
	(reg horas_contrato_tp1 horas_contrato_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 &  abs(st_ind25) <= 1.5 & cut25< mean_cut25_mv, vce(cluster rbd)) ///
	(reg horas_contrato_tp1 horas_contrato_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 &  abs(st_ind10) <= 1.5 & cut10< mean_cut10_mv, vce(cluster rbd)) /// 
	(reg horas_contrato_tp1 horas_contrato_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 &  abs(st_ind25) <= 1.5 & cut25>=mean_cut25_mv, vce(cluster rbd)) ///
	(reg horas_contrato_tp1 horas_contrato_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 &  abs(st_ind10) <= 1.5 & cut10>=mean_cut10_mv, vce(cluster rbd)) /// 
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 &  abs(st_ind25) <= 1.5 & cut25< mean_cut25_mv, vce(cluster rbd)) ///
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 &  abs(st_ind10) <= 1.5 & cut10< mean_cut10_mv, vce(cluster rbd)) /// 
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 &  abs(st_ind25) <= 1.5 & cut25>=mean_cut25_mv, vce(cluster rbd)) ///
	(reg tea_classhrs_tp1 	tea_classhrs_tm1  	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 &  abs(st_ind10) <= 1.5 & cut10>=mean_cut10_mv, vce(cluster rbd)) /// 
	, ///
	indepvars(	treat25, treat10,treat25, treat10,  /// 
				treat25, treat10,treat25, treat10,  ///
				treat25, treat10,treat25, treat10,  ///
				treat25, treat10,treat25, treat10,  ///
				treat25, treat10,treat25, treat10,  ///
				treat25, treat10,treat25, treat10  /// 
			) seed(12011303)  cluster(rbd) strata(sned_yr) idcluster(newclusterid) usevalid reps(500) //holm
		
matrix RW=e(RW)		


matrix list RW

foreach v of numlist 1(1)24{ // each variable is a row in RW

scalar rw_pv=RW[`v',3]
scalar h_pv =RW[`v',4]
estadd scalar rw_pv : est`v'
estadd scalar h_pv :  est`v' 

}

*   


local sample="all"
esttab est1 est2 est3 est4 est5 est6 est7 est8 using "$output_dir/post_t_extval_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2  rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"'  `"Romano-Wolf p-value"' ))

local sample="pv"
esttab est9 est10 est11 est12 est13 est14 est15 est16 using "$output_dir/post_t_extval_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2  rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"'  `"Romano-Wolf p-value"' ))

local sample="mv"
esttab est17 est18 est19 est20 est21 est22 est23 est24 using "$output_dir/post_t_extval_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2  rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"'  `"Romano-Wolf p-value"' ))




eststo clear				


				
*----------------------------------   end
				
				
				
				
				
				
	
